<?php

namespace framework\session;

/**
 * session redis 驱动类
 */
class redisDriver extends \SessionHandler {

    private $ttl = 7200;       /* 2小时 */
    private $namespace = 'session_';

    public function read($session_id): string {
        return (string) \framework\nosql\Redis::getInstance()->get($this->namespace . $session_id);
    }

    public function write($session_id, $session_data): bool {
        \framework\nosql\Redis::getInstance()->set($this->namespace . $session_id, $session_data, $this->ttl);
        return true;
    }

    public function destroy($session_id): bool {
        \framework\nosql\Redis::getInstance()->delete($this->namespace . $session_id);
        return true;
    }

}
